'use strict';

const Controller = require('egg').Controller;

class DbController extends Controller {
  async getDb(tabber, data) {
    const list = await this.app.mysql.select(tabber, data);
    return list
  }
  async addDb(tabber, data) {
    const list = await this.app.mysql.insert(tabber, data);
    return list
  }
  async  getTotal(tabber, { where }) {
    var data = { // 搜索 post 表
      where: { isdel: 0 }, // WHERE 条件
      columns: ['id'], // 要查询的表字段
    }
    data.where = {
      ...data.where,
      ...where
    }
    var list = await this.app.mysql.select(tabber, data);
    return list.length
  }
  async updataDb(tabber, data) {
    const list = await this.app.mysql.update(tabber, data);
    return list
  }

  async linkDb(tabber, data) {
    var where = data.where;
    var sqlStr = '';
    for (const key in object) {
      if (object.hasOwnProperty(key)) {
        const element = object[key];

      }
    }

    var sql = `SELECT * FROM ${table} WHRER `

    // res.data = await this.app.mysql.query(`SELECT * FROM category WHERE subcategory Link '%?%' and title Link '%?%' LIMIT ?,?`, [subcategory, title, data.offset, data.limit]);

    const list = await this.app.mysql.update(tabber, data);

    return list
  }

}

module.exports = DbController;
